<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册界面</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            margin: 0;
            padding: 0;
        }

        .register-container {
            max-width: 400px;
            margin: 100px auto;
            padding: 20px;
            background: #fff;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }

        .register-container h2 {
            text-align: center;
            color: #333;
            margin-bottom: 20px;
        }

        .form-group {
            margin-bottom: 15px;
        }

        .form-group label {
            display: block;
            margin-bottom: 5px;
            color: #666;
        }

        .form-group input {
            width: 100%;
            padding: 10px;
            border: 1px solid #ccc;
            border-radius: 4px;
            box-sizing: border-box;
        }

        .form-group input:focus {
            border-color: #007bff;
            outline: none;
        }

        .form-group button {
            width: 100%;
            padding: 10px;
            background-color: #007bff;
            border: none;
            border-radius: 4px;
            color: #fff;
            cursor: pointer;
            font-size: 16px;
        }

        .form-group button:hover {
            background-color: #0056b3;
        }

        .form-group .error {
            color: red;
            font-size: 14px;
            margin-top: 5px;
        }

        .login-link {
            text-align: center;
            margin-top: 10px;
        }

        .login-link a {
            color: #007bff;
            text-decoration: none;
        }

        .login-link a:hover {
            text-decoration: underline;
        }
    </style>
</head>
<body>
    <div id="app" class="register-container">
        <h2>注册</h2>
        <div class="form-group">
            <label for="username">用户名</label>
            <input type="text" id="username" v-model="user.username" placeholder="请输入用户名">
        </div>
        <div class="form-group">
            <label for="password">密码</label>
            <input type="password" id="password" v-model="user.password" placeholder="请输入密码">
        </div>
        <div class="form-group">
            <button type="button" @click="register">注册</button>
        </div>
        <div class="login-link">
            <a href="../../login.html">已有账号？去登录</a>
        </div>
    </div>

    <script type="text/javascript" src="../../js/vue.js"></script>
    <script type="text/javascript" src="../../js/axios-0.18.0.js"></script>
    <script>
        new Vue({
            el: "#app",
            data: {
                user: {}
            },
            methods: {
                register: function() {
                    axios.post("http://localhost:8080/users/register", this.user)
                        .then(res => {
                            if (res.data.code == 200) {
                                alert("注册成功");
                                window.location.href = "./login.html"; // 注册成功后跳转到登录页面
                            } else {
                                alert(res.data.msg);
                            }
                        })
                        .catch(err => {
                            console.log(err);
                        });
                }
            }
        });
    </script>
</body>
</html>